---
title: Server-side clients
sidebar:
  order: 20
---

import { Code, Tabs, TabItem } from '@astrojs/starlight/components';

You can also use LiveStore on the server side e.g. via the `@livestore/adapter-node` adapter. This allows you to:
- have an up-to-date server-side SQLite database (read model)
- react to events / state changes on the server side (e.g. to send emails/push notifications)
- commit events on the server side (e.g. for sensitive/trusted operations)

![](https://share.cleanshot.com/9gG45pWJ+)

Note about the schema: While the `events` schema needs to be shared across all clients, the `state` schema can be different for each client (e.g. to allow for a different SQLite table design on the server side).

## Example

<Tabs>
  <TabItem label="main.ts">
    <Code lang="ts" code={`\
  import { makeAdapter } from '@livestore/adapter-node'
  import { createStorePromise } from '@livestore/livestore'
  import { makeCfSync } from '@livestore/sync-cf'

  import { events, schema, tables } from './livestore/schema.js'

  const adapter = makeAdapter({
    storage: { type: 'fs', baseDirectory: 'tmp' },
    sync: { backend: makeCfSync({ url: 'ws://localhost:8787' }), onSyncError: 'shutdown' },
  })

  const store = await createStorePromise({
    adapter,
    schema,
    storeId: 'test',
    syncPayload: { authToken: 'insecure-token-change-me' },
  })

  const todos = store.query(tables.todos.where({ completed: false }))
    `} />
  </TabItem>
  <TabItem label="schema.ts">
    <Code lang="ts" code={`\
  import { makeSchema } from '@livestore/livestore'

  const events = // ...
  const state = // ...

  export const schema = makeSchema({ events, state })
    `} />
  </TabItem>
</Tabs>

## Further notes

### Cloudflare Workers

- The `@livestore/adapter-node` adapter doesn't yet work with Cloudflare Workers but you can follow [this issue](https://github.com/livestorejs/livestore/issues/266) for a Cloudflare adapter to enable this use case.
- Having a `@livestore/adapter-cf-worker` adapter could enable serverless server-side client scenarios.
